package wang.aweb.childcar.controller.management;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import wang.aweb.childcar.common.ApiRestResponse;
import wang.aweb.childcar.service.CzOrderService;
import wang.aweb.childcar.service.DeviceService;
import wang.aweb.childcar.service.MemberService;
import wang.aweb.childcar.service.OrderService;
import wang.aweb.childcar.util.MonthDataUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/management/census/")
public class CensusController {
    @Autowired
    private DeviceService deviceService;
    @Autowired
    private OrderService orderService;
    @Autowired
    private MemberService memberService;
    @Autowired
    private CzOrderService czOrderService;
    @GetMapping("index")
    public ApiRestResponse index(){
        Map<String,Object> dataMap=new HashMap<>();
        Integer freeDeviceCount=deviceService.getFreeCount();
        Integer deviceCount=deviceService.getDeviceCount();
        Integer orderCount=orderService.getOrderCount();
        Integer orderMonthCount=orderService.getOrderMonthCount();
        Integer orderDayCount=orderService.getOrderDayCount();
        Integer moneyCount=czOrderService.getMoneyOrderCount();
        Integer moneyMonthCount=czOrderService.getMoneyOrderMonthCount();
        Integer moneyDayCount=czOrderService.getMoneyOrderDayCount();
        Integer userCount=memberService.getUserCount();
        Integer userDayCount=memberService.getUserDayCount();
        Date now=new Date();
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat sdf1=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        dataMap.put("month", MonthDataUtils.getMonthBegin(sdf.format(now)));
        dataMap.put("day",MonthDataUtils.getDayStart(sdf.format(now)));
        dataMap.put("freeDeviceCount",freeDeviceCount);
        dataMap.put("deviceCount",deviceCount);
        dataMap.put("orderCount",orderCount);
        dataMap.put("orderMonthCount",orderMonthCount);
        dataMap.put("orderDayCount",orderDayCount);
        dataMap.put("moneyCount",moneyCount);
        dataMap.put("moneyMonthCount",moneyMonthCount);
        dataMap.put("moneyDayCount",moneyDayCount);
        dataMap.put("userCount",userCount);
        dataMap.put("userDayCount",userDayCount);
        return ApiRestResponse.success(dataMap);
    }
}
